/**
 * Created by dale on 2017/10/23.
 */
// $(document).ready(function () {
//     // window.webkit.messageHandlers.setBarColor.postMessage({color:'#0066cc'});
//     $('#logout').click(function () {
//
//
//     });
// });


$(function () {
    try{
        window.top.chageColor('#0066cc');
        // window.webkit.messageHandlers.setBarColor.postMessage({color:'#0066cc'});
    }catch (Expection){

    }
   obj.init();
});
var obj = new function () {
  'use strict';
  return {
      dom:{
          logout: null,
          setPwd: null,
          scan:   null
      },
      init: function () {
          this.dom.logout = $('#logout');
          this.dom.setPwd = $('#restPwd');
          this.dom.scan   = $('#scan');
          this.listener();
      },
      listener:function () {
          var $this = this;
          //登出
          $this.dom.logout.click(function () {
              $this.funObj().logOut();
          });
          //设置密码
          $this.dom.setPwd.click(function () {
              $this.funObj().setPwd(this);
          });
          //扫一扫
          $this.dom.scan.click(function () {
              $this.funObj().scan();
          });
          
          $('#trustDev').click(function () {
              $this.funObj().trustDevList(this);
          })

      },
      funObj: function () {
          var $this = this;
          return {
              logOut: function () {
                  $this.dom.logout.linkbutton({
                      text:'注销中...',
                      disabled:true
                  });
                  $.ajax({
                      url:baseUrl+'frontend/index/SignOut',
                      type:'post',
                      complete:function () {
                          $.ajax({
                              url:baseUrl+'mobile/mine/destoryCookie',
                              type:'post',
                              complete:function () {
                                  window.top.location.reload();
                              }
                          });

                      }
                  });
              },
              setPwd: function (target) {
                  var text = $(target).text();
                  var id   = $(target).attr('nodeId');
                  $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/mine/changePwd');
                  window.parent.setTitle("修改密码");
                  window.parent.goTarget();
              },
              scan: function () {
                  // window.webkit.messageHandlers.openScanf.postMessage(null);
                  window.top.openScan();
              },
              trustDevList:function (target) {
                  var text = $(target).text();
                  $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/mine/trustDevList');
                  window.parent.setTitle(text);
                  window.parent.goTarget();
              }
          };
      }
  }
};
/**
 * 扫码回调
 * @type {{setResult: JSObjectHandle.setResult}}
 * created by dale 2017/9/15
 */
var JSObjectHandle={
    setResult:function (code) {
        setTimeout(function () {
            $('#targetFrame',window.parent.document).attr('src',code);
            window.parent.setTitle("扫码结果");
            window.parent.goTarget();
        },0);
    }
};